package mysql

import "gorm.io/gorm"

type User struct {
	gorm.Model
	Username  string `gorm:"type:varchar(20);not null;comment:用户名"`
	Tel       string `gorm:"type:char(11);not null;comment:手机号"`
	Password  string `gorm:"type:varchar(32);not null;comment:密码"`
	HeadImage string `gorm:"type:varchar(500);not null;comment:头像"`
	Age       int64  `gorm:"type:int(11);not null;comment:年龄"`
	Address   string `gorm:"type:varchar(30);not null;comment:籍贯"`
	Email     string `gorm:"type:varchar(50);not null;comment:邮箱"`
}

func (u *User) FirstOrCreateUser(db *gorm.DB, tel string) error {
	return db.Debug().Where("tel=?", tel).FirstOrCreate(u).Error
}

func (u *User) FindUserByUserId(db *gorm.DB, id int64) error {
	return db.Debug().Where("id=?", id).First(u).Error
}

func (u *User) UpdateUserByPassword(db *gorm.DB) error {
	return db.Debug().Updates(u).Error
}

func (u *User) UpdateUser(db *gorm.DB) error {
	return db.Debug().Updates(u).Error
}
